package main.utils;

import javafx.scene.Group;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import main.entity.Raft;

public class RiverFactory implements RiverConstants {

    public static Group createContent() {
        Group content = new Group();
        Image grassImage = new Image("main/resources/img/grass.jpg", CELL_SIZE, CELL_SIZE, false, false);
        Image waterImage = new Image("main/resources/img/water.gif", CELL_SIZE, CELL_SIZE, false, false);


        GridDisplay pane = new GridDisplay();

        BorderPane mainPanel = new BorderPane();
        mainPanel.setCenter(pane.getDisplay());

        for (int col = 0; col < CELLS_COUNT; col++) {
            pane.add(new ImageView(grassImage), col, 0);
        }
        for (int col = 0; col < CELLS_COUNT; col++) {
            for (int row = 1; row < CELLS_COUNT - 1; row++) {
                pane.add(new ImageView(waterImage), col, row);
            }
        }
        for (int col = 0; col < CELLS_COUNT; col++) {
            pane.add(new ImageView(grassImage), col, CELLS_COUNT - 1);
        }
        content.getChildren().add(pane.getDisplay());

        return content;
    }

    public static Group createPopup() {
        Group popup = new Group();
        popup.setVisible(false);

        Rectangle popupGlass = new Rectangle();
        popupGlass.setFill(new Color(0, 0, 0, 0.5));
        popupGlass.setX(0);
        popupGlass.setY(0);
        popupGlass.setWidth(RiverConstants.FRAME_SIZE);
        popupGlass.setHeight(RiverConstants.FRAME_SIZE);
        popup.getChildren().add(popupGlass);
        Text t = new Text(150, 150, "You have crushed. Press Space.");
        t.setFont(new Font(20));
        t.setFill(Color.WHITE);
        popup.getChildren().add(t);
        return popup;
    }

    public static Raft createRaft() {
        int raftX = RAFT_X_POSITION;
        int raftY = FRAME_SIZE / 2 - RAFT_HEIGHT;

        return new Raft(raftX, raftY);
    }

}
